/**
 * 公告添加
 * @param exports
 * @returns
 */
layui.define(['common','api','form','layer','laydate'],function(exports){
	var laytpl = layui.laytpl;
	var $ = layui.jquery;
	var form = layui.form();
	var layer = layui.layer;
	var laydate = layui.laydate;

	var api = layui.api;
	var common = layui.common;

	//监听提交
	form.on('submit(formDemo)', function(data){
		var val = Date.parse(data.field['start']);
		data.field['start'] = new Date(val);
		val = Date.parse(data.field['end']);
		data.field['end'] = new Date(val);
		api.addNotice(data.field,function(res){
			if(res.status == 200){
				layer.alert("新增成功", {
		          icon: 1,
		          end:function(){
		          	location.href = '/blog/back/notice';
		          }
				});
			} else {
				layer.msg(res.msg || res.status, {
					shift: 6
				});
			}
		});
		return false;
	});

	var start = {
		min: laydate.now()
		,max: '2099-06-16 23:59:59'
		,istoday: false
		,choose: function(datas){
			end.min = datas; //开始日选好后，重置结束日的最小日期
			end.start = datas //将结束日的初始值设定为开始日前段日期字符串如何映射到对象的中的日期
		}
	};
	var end = {
		min: laydate.now()
		,max: '2099-06-16 23:59:59'
		,istoday: false
		,choose: function(datas){
			start.max = datas; //结束日选好后，重置开始日的最大日期
		}
	};
	$("#notice-start").on("click",function(){
		start.elem = this;
		laydate(start);
	});
	$("#notice-end").on("click",function(){
		end.elem = this
		laydate(end);
	});

	exports('notice-add',{});

});